package org.example.app.order.service;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import org.example.app.order.executor.OrderCreateCmdExe;
import org.example.app.order.executor.query.OrderGetByOrderNoQueryExe;
import org.example.client.order.api.OrderServiceI;
import org.example.client.order.dto.clientobject.OrderCO;
import org.example.client.order.dto.cmd.OrderCreateCmd;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class OrderServiceImpl implements OrderServiceI {

    @Resource
    private OrderGetByOrderNoQueryExe orderGetByOrderNoQueryExe;
    @Resource
    private OrderCreateCmdExe orderCreateCmdExe;

    @Override
    public SingleResponse<OrderCO> getByOrderNo(String orderNo) {
        return orderGetByOrderNoQueryExe.execute(orderNo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Response createOrder(OrderCreateCmd orderCreateCmd) {
        return orderCreateCmdExe.execute(orderCreateCmd);
    }
}